<?php
declare (strict_types=1);

namespace app\admin\controller\advertiser;

use app\admin\service\advertiser\AdvertiserUserService;
use app\BaseController;
use upload\ImgUpload;
use think\facade\Request;
use think\response\Json;

/**
 * 广告主用户管理
 */
class AdvertiserUser extends BaseController
{
    /**
     * 广告主图片文件上传
     * @return Json
     */
    public function imageUpload(): Json
    {
        $file = request()->file('picture');
        if (!$file) {
            return jsonReturn(0, [], '图片参数错误');
        }
        //处理上传图片信息
        $picture = ImgUpload::imgUploadAliyun($file, 'advertiser/picture', 0, 0, 1000);
        return jsonReturn(1, $picture, '上传成功');
    }

    /**
     * 广告主用户列表
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function list(AdvertiserUserService $advertiserUserService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['name'] = Request::param('name/s');
        $params['phone'] = Request::param('phone/d');
        $params['enable'] = Request::param('enable/d');
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        return $advertiserUserService->list($params);
    }

    /**
     * 广告主全部用户列表
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function listAll(AdvertiserUserService $advertiserUserService): Json
    {
        $params['name'] = Request::param('name/s');
        return $advertiserUserService->listAll($params);
    }

    /**
     * 广告主用户禁用或启用
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function enable(AdvertiserUserService $advertiserUserService): Json
    {
        $params['id'] = Request::param('id/d', 0);
        $params['enable'] = Request::param('enable/d', 2);
        return $advertiserUserService->enable($params['id'], $params['enable']);
    }

    /**
     * 广告主充值
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function recharge(AdvertiserUserService $advertiserUserService): Json
    {
        $params['ad_user_id'] = Request::param('ad_user_id/d', 0);//广告主ID
        $params['actual_pay'] = Request::param('actual_pay/f', 0.0);//实际支付金额
        $params['arrival_pay'] = Request::param('arrival_pay/f', 0.0);//到账金额
        return $advertiserUserService->recharge($params);
    }

    /**
     * 广告主充值记录
     * @param AdvertiserUserService $advertiserUserService
     * @return Json
     */
    public function rechargeList(AdvertiserUserService $advertiserUserService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        return $advertiserUserService->rechargeList($params);
    }


}
